home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Financial / Stopwatch2.3 / Source / SessionViewMgr.m < prev    next >
Text File  |  1995-06-12  |  2KB  |  121 lines

  1. /*
  2.  * For legal stuff see the file COPYRIGHT
  3.  */
  4. #import "SessionViewMgr.h"
  5. #import "ClientInspector.h"
  6. #import "SessionEditor.h"
  7. #import "Controller.h"
  8.  
  9. @interface SessionViewMgr(PRIVATE)
  10. - (void)displayTotalMins;
  11. - (void)displayClientMins;
  12. - (float)totalBillings;
  13. - (int)totalMins;
  14. @end
  15.  
  16. @implementation SessionViewMgr
  17.  
  18. - itemEditor
  19. {
  20.   return [SessionEditor new];
  21. }
  22.  
  23. /*
  24.  * Provide the add, delete and sort methods to invoke on ClientInfo objects
  25.  */
  26. - (SEL)addMethod
  27. {
  28.   return @selector(addSession:);
  29. }
  30.  
  31. - (SEL)deleteMethod
  32. {
  33.   return @selector(deleteSession:);
  34. }
  35.  
  36. - (SEL)sortMethod
  37. {
  38.   return @selector(sortSessions);
  39. }
  40.  
  41.  
  42. - info:(ClientInfo *)info itemAt:(int)position
  43. {
  44.   return [info sessionAt:position];
  45. }
  46.  
  47. - (int)itemCount:(ClientInfo *)info 
  48. {
  49.   return [info sessionCount];
  50. }
  51.  
  52. - (void)displaySummary
  53. {
  54.   [self displayClientMins];
  55.   [self displayTotalMins];
  56. }
  57.  
  58. @end
  59.  
  60.  
  61. @implementation SessionViewMgr(PRIVATE)
  62.  
  63. - (float)totalBillings
  64. {
  65.   float billings = 0.0;
  66.   List *clientList = [[NXApp delegate] clientList];
  67.   int i, count = [clientList count];
  68.  
  69.   for ( i = 0; i < count; i++ )
  70.     billings += [[clientList objectAt:i] totalBillable];
  71.  
  72.   return billings;
  73. }
  74.  
  75. - (int)totalMins
  76. {
  77.   List *clientList = [[NXApp delegate] clientList];
  78.   int i, count = [clientList count];
  79.   int totalMins = 0;
  80.  
  81.   for ( i = 0; i < count; i++ )
  82.     totalMins += [[clientList objectAt:i] totalMins];
  83.  
  84.   return totalMins;
  85. }
  86.  
  87. - (void)displayClientMins
  88. {
  89.   id info = [[ClientInspector sharedInstance] selectedClient];
  90.  
  91.   if ( info ) {
  92.     char buf[20];
  93.     sprintf( buf, "%.2f", [info totalHours] );
  94.     [clientHoursField setStringValue:buf];
  95.  
  96.     sprintf( buf, "$%.2f", [info totalBillable] );
  97.     [clientBillingsField setStringValue:buf];
  98.   } else {
  99.     [clientHoursField    setStringValue:""];
  100.     [clientBillingsField setStringValue:""];
  101.   }
  102. }
  103.  
  104. /*
  105.  * Display the total minutes and billings, and for the
  106.  * currently selected client.
  107.  */
  108. - (void)displayTotalMins
  109. {
  110.   char buf[10];
  111.   float hours = [self totalMins]/60.0;
  112.  
  113.   sprintf( buf, "%.2f", hours );
  114.   [totalHoursField setStringValue:buf];
  115.  
  116.   sprintf( buf, "$%.2f", [self totalBillings] );
  117.   [totalBillingsField setStringValue:buf];
  118. }
  119.  
  120. @end
  121.